package com.mall.service.homepage.controller;

import com.mall.commons.common.CommonPage;
import com.mall.commons.common.CommonResult;
import com.mall.model.domain.CmsSubject;
import com.mall.service.homepage.service.SubjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author Pan Rundong
 * @Date 2023-03-13 14:27
 * @Desc 商品专题Controller
 */
@RestController
@RequestMapping("subject")
@Slf4j
public class SubjectController {
    @Autowired
    private SubjectService subjectService;

    /**
     * 分页获取商品专题
     *
     * @param
     * @return com.mall.commons.common.CommonPage<com.mall.model.domain.CmsSubject>
     * @Author Pan Rundong
     */
    @GetMapping("list")
    public CommonResult<CommonPage<CmsSubject>> list(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             String keyword)
    {
        log.info("pageNum = {}, pageSize = {}, keyword = {}", pageNum, pageSize, keyword);
        CommonPage<CmsSubject> page = subjectService.getPage(pageNum, pageSize, keyword);
        return CommonResult.success(page, "成功获取商品专题");
    }

    /**
     * 获取全部商品专题
     *
     * @param
     * @return com.mall.commons.common.CommonResult<java.util.List < com.mall.model.domain.CmsSubject>>
     * @Author Pan Rundong
     */
    @GetMapping("listAll")
    public CommonResult<List<CmsSubject>> listAll() {
        log.info("获取全部商品专题");
        List<CmsSubject> cmsSubjects = subjectService.list();
        return CommonResult.success(cmsSubjects, "获取商品专题成功");
    }
}
